home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Freeware / DiskMaster / Rexx / DMMultiRename.rexx < prev    next >
OS/2 REXX Batch file  |  2002-10-27  |  3KB  |  123 lines

  1. /* $VER: DMMultiRename.rexx 1.1 (2.10.98) by J.Tierney
  2.  
  3.   DiskMaster II Multi-Rename  v1.1
  4.   10/2/98  by J. Tierney <jtierney@cyberlink-inc.com>
  5.   Began:  2/8/98
  6.  
  7.  
  8.   Function:  Rename all selected files in a similar manner, possibly
  9.             stripping file extensions and adding index numbers.
  10.  
  11.             A requester will ask for a pattern, which may be:
  12.  
  13.   Patterns:  *    - Old name.
  14.              -.   - Strip extension.  May be used more than once.  No effect if
  15.                    an extension isn't found.  Use with "*".
  16.              +n   - Index.  <n> = starting number.  Each "+" will be one digit.
  17.                     Ex:  +5  = "5", "6", "7", ...
  18.                          ++2 = "02", "03", "04", ...
  19.                          +++ = "000", "001", "002", ...
  20.  
  21.              All other text will become part of the new file name.
  22.  
  23.  
  24.   Usage:  AddCmd MultiRename, 10, REXX REXX:DMMultiRename.rexx
  25.  
  26.  
  27.   Examples:
  28.     Selected files = "Whipple.guide.xpk", "Bla.txt", "Fruit.jpg"
  29.  
  30.     Pattern:  *-.
  31.      Result:  "Whipple.guide", "Bla", "Fruit"
  32.               Same name, strip one extension.
  33.  
  34.     Pattern:  *-.-.-.
  35.      Result:  "Whipple", "Bla", "Fruit"
  36.               Same name, strip three extensions.
  37.  
  38.     Pattern:  *.bak
  39.      Result:  "Whipple.guide.xpk.bak", "Bla.txt.bak", "Fruit.jpg.bak"
  40.               Same name, append ".bak".
  41.  
  42.     Pattern:  File+++5L
  43.      Result:  "File005L", "File006L", "File007L"
  44.               Rename all the files to "File###L", where "###" is a 3 number
  45.              index beginning at 5.
  46.  
  47.     Pattern:  *-.-.-..fake
  48.      Result:  "Whipple.fake", "Bla.fake", "Fruit.fake"
  49.               Same name, strip three extensions, append ".fake".
  50.  
  51. */
  52.  
  53. OPTIONS RESULTS
  54.  
  55. 'CONFIRM "Enter new name:" Okay Cancel *-.-.++1'
  56.  
  57. pat = result
  58.  
  59. DIRLIST VAR dlist SEL
  60.  
  61. STATUS P
  62. path = result
  63. IF RIGHT(path, 1) ~= ':' THEN path = path || '/'
  64.  
  65. idx.places = ''
  66.  
  67. DO i = 1 TO dlist.name.0
  68.   newname = MakeNewName(pat, dlist.name.i)
  69.   'RENAME' path || dlist.name.i path || newname
  70. END
  71.  
  72. 'DESELECT *'
  73. EXIT 0
  74.  
  75.  
  76. MakeNewName:  PROCEDURE EXPOSE idx.
  77.   PARSE ARG pat, oldname
  78.  
  79.   /* Index? */
  80.   s = POS('+', pat)
  81.   IF s > 0 THEN DO
  82.     IF idx.places = '' THEN DO
  83.       DO x = 1 UNTIL SUBSTR(pat, s + x, 1) ~= '+'
  84.       END
  85.       idx.places = x
  86.  
  87.       DO n = 0 UNTIL ~DATATYPE(SUBSTR(pat, s + x + n, 1), 'N')
  88.       END
  89.       idx.extra = n
  90.       IF n > 0 THEN DO
  91.         str = SUBSTR(pat, s + x, n)
  92.         idx.num = str - 1
  93.         END
  94.       ELSE DO
  95.         idx.num = -1
  96.       END
  97.     END
  98.  
  99.     pat = DELSTR(pat, s, idx.places + idx.extra)
  100.     idx.num = idx.num + 1
  101.     pat = INSERT(RIGHT(idx.num, idx.places, '0'), pat, s - 1)
  102.   END
  103.  
  104.   /* Strip extension? */
  105.   DO UNTIL s = 0
  106.     s = POS('-.', pat)
  107.     IF s > 0 THEN DO
  108.       x = LASTPOS('.', oldname)
  109.       IF x > 0 THEN oldname = LEFT(oldname, x - 1)
  110.       pat = DELSTR(pat, s, 2)
  111.     END
  112.   END
  113.  
  114.   /* Sandwich the old name between the new bits? */
  115.   s = POS('*', pat)
  116.   IF s > 0 THEN DO
  117.     pat = DELSTR(pat, s, 1)
  118.     pat = INSERT(oldname, pat, s - 1)
  119.   END
  120.  
  121. RETURN pat
  122.  
  123.